
#include "slot_line_util.h"
#include <cstdlib>



namespace tf_op {


void SlotLineSplit(const string& slot_line, vector<string>& tokens, const string& delimiter) {

    string::size_type last_pos = slot_line.find_first_not_of(delimiter, 0);
    string::size_type pos = slot_line.find_first_of(delimiter, last_pos);

    while (string::npos != pos || string::npos != last_pos) {
        tokens.push_back(slot_line.substr(last_pos, pos-last_pos));
        last_pos = slot_line.find_first_not_of(delimiter, pos);

        // 最后面有空字符是不会填一个空string的
        AddEmptyToken(tokens, last_pos-pos, delimiter.size());

        pos = slot_line.find_first_of(delimiter, last_pos);
    }

}

void AddEmptyToken(vector<string>& tokens, const int& step, const int& delimiter_size) {
    int empty_step = (step/delimiter_size)-1;
    for (int i = 0; i < empty_step; i++) {
        tokens.emplace_back("");
    }
}



}



